package com.androidvizlab.bachelor.customcomponents.viewholder;

import com.androidvizlab.bachelor.R;
import com.androidvizlab.bachelor.datamodels.CameraGroup;
import com.androidvizlab.bachelor.datamodels.UniqueCamGroups;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Is used for adding views on the ListView within the fragment.
 * Mainly used for displaying groups of triplets camera groups.
 * @author TheHive
 */
public class CamComboListViewHolder extends ListViewHolder{

	private TextView grpName = null;
	private TextView s0 = null;
	private TextView mean = null;
	private TextView max = null;
	private TextView nrFrames = null;
	
	private TextView tv = null;
	private LinearLayout container = null;
	private LinearLayout.LayoutParams layoutParams = null;
	private LinearLayout.LayoutParams tvLayoutParams = null;
	
	public CamComboListViewHolder(View view) 
	{
		super(view);
		
		/*
		grpName = (TextView) view.findViewById(R.id.tvCamGrp);
		s0 = (TextView) view.findViewById(R.id.tvS0);
		mean = (TextView) view.findViewById(R.id.tvMean);
		max = (TextView) view.findViewById(R.id.tvMax);
		nrFrames = (TextView) view.findViewById(R.id.tvNrFrames);
		*/
	}
	
	/**
	 * Adds rows on the ListView depending on how many items in the UniqueCamgroups
	 * @param obj 
	 */
	public void addRowElements(Object obj)
	{
		if(obj != null && obj instanceof UniqueCamGroups)
		{
			Log.i("viewHolder","reached");
			UniqueCamGroups grps = (UniqueCamGroups)obj;
			
			for(CameraGroup cg : grps.getGroups())
			{
				container = new LinearLayout(view.getContext());
				container.setOrientation(LinearLayout.HORIZONTAL);
				layoutParams = new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
				layoutParams.setMargins(0,0,0,5);
				
				container.setLayoutParams(layoutParams);
				tv = new TextView(view.getContext());
				tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.5f);
				tv.setLayoutParams(tvLayoutParams);
				tv.setText(cg.getGroupName());
				
				container.addView(tv);
				
				tv = new TextView(view.getContext());
				tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
				tv.setLayoutParams(tvLayoutParams);
				tv.setText(Double.toString(cg.getS0()));
				
				container.addView(tv);
				
				tv = new TextView(view.getContext());
				tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
				tv.setLayoutParams(tvLayoutParams);
				tv.setText(Double.toString(cg.getMean()));
				
				container.addView(tv);
				
				tv = new TextView(view.getContext());
				tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
				tv.setLayoutParams(tvLayoutParams);
				tv.setText(Double.toString(cg.getMax()));
				
				container.addView(tv);
				
				tv = new TextView(view.getContext());
				tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
				tv.setLayoutParams(tvLayoutParams);
				tv.setText(Integer.toString(cg.getNoOfFramesUsed()));
				
				container.addView(tv);
				
				((LinearLayout)view).addView(container);
			}	
			
			tv = new TextView(view.getContext());
			tvLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
			tv.setLayoutParams(tvLayoutParams);
			tv.setText("Av. S0: "+Double.toString(grps.getAvgS0()));
			
			((LinearLayout)view).addView(tv);
		}
	}
	
	//not in use
	@Override
	public void setTVText(String... params)
	{
		this.grpName.setText(params[0]);
		this.s0.setText(params[1]);
		this.mean.setText(params[2]);
		this.max.setText(params[3]);
		this.nrFrames.setText(params[4]);
	}	
}
